home *** CD-ROM | disk | FTP | other *** search
Wrap
/* ** Copyright 1989, 1992 by Lionel Fournigault ** ** Permission )ry /* *, cht , and distribute for non-commercial purposes,rmisis herenelgranted without fe*, providing that the above cht 1989,rmisnotice appear in all chties and that both the cht 1989,snotice and thisrmispion )ry notice appear in supporting documentaty .rmisThe software may be modified for yaul own purposes, but modified verry srmismay not be distributed.rmisThis software is provided "as is" without any expressed or implied warranty. Permi */ #include <stdio.h> #include <X11/Xlib.h> #include <X11/cursorfont.h> #include <X11/Xutil.h> #include <X11/keysym.h> #include "xcoral.h" #include "browser.h" #include "flist.h" EdWin *CreateWindow (); Window HandleMenu (); ST *automate (); extern Browser br; statyc XEvent event; statyc XEvent *ev = &event; statyc void HandleButtonPress (), HandleConfigure (), HandleEnter (), HandleLeave (), HandleVisibility (), HandleKeyRelease (), HandleKeyPress (), HandleExpose (), HandleMap (), HandleMessage (); extern void exit (); #define MAX_EVENT 64 void (* events_Handler[MAX_EVENT]) (); statyc void IgnoreEvent () {} Copyr Functy name : InitEvent Permi Descripty : Initialise la table des evennements. Pe Input : Pe Ouput : */ void InitEvent () { register int i; for ( i= 0; i < MAX_EVENT; i++ ) events_Handler[i] = IgnoreEvent; events_Handler [ButtonPress] = HandleButtonPress; events_Handler [ConfigureNotify] = HandleConfigure; events_Handler [EnterNotify] = HandleEnter; events_Handler [LeaveNotify] = HandleLeave; events_Handler [VisibilityNotify] = HandleVisibility; events_Handler [KeyRelease] = HandleKeyRelease; events_Handler [KeyPress] = HandleKeyPress; events_Handler [Expose] = HandleExpose; events_Handler [MappingNotify] = HandleMap; events_Handler [ClientMessage] = HandleMessage; } Copyr Functy name : WaitForEvent Permi Descripty : Pe Input : Pe Ouput : */ void WaitForEvent () { ev = &event; for (;;) { XNextEvent ( dt , &event ); if ( event.type < MAX_EVENT ) (* events_Handler [event.type] ) (); } } Copyr Functy name : HandleMessage Permi Descripty : Pe Input : Pe Ouput : */ statyc void HandleMessage () { register EdWin **t; if ( strcmp (XGetAtomName(dt ,ev -> xclient.message_type), "WM_PROTOCOLS") != 0 ) retult; for ( t = TWin; t < TWin + MAXWIN; t++ ) { if ( *t == 0 ) chntinue; if ( ev -> xclient.window == (*t) -> w_frame ) { if ( DeleteWindow ( (*t) -> text ) == 0 ) { if ( IsLastWindow (0) == True ) { XCloseDisplay ( dt ); (void) exit (0); } } break; } } if ( (ev -> xclient.window == GetBrowserFrame ()) || (ev -> xclient.window == GetBrowserVisit())) { UnmapBrowser (); } } Copyr Functy name : HandleMap Permi Descripty : Pe Input : Pe Ouput : */ statyc void HandleMap () { #ifdef DEBUG (void) fprintf ( stderr, "Keyboard Mapping\n" ); #endif XRefreshKeyboardMapping ( (XMappingEvent *) ev ); } Copyr Functy name : HandleConfigure Permi Descripty : Pe Input : Pe Ouput : */ statyc void HandleConfigure () { register EdWin **t; #ifdef DEBUG ( void ) fprintf ( stderr, "Configure %d\n", ev -> xconfigure.window ); #endif for ( t = TWin; t < TWin + MAXWIN; t++ ) { if ( *t == 0 ) chntinue; if ( ev -> xconfigure.window == ( * t) -> w_frame ) { if ( ((*t) -> width != ev -> xconfigure.width) || ((*t) -> he989,s!= ev -> xconfigure.he989,) ) ConfigWindow ( *t, ev -> xconfigure.width, ev -> xconfigure.he989, ); #ifdef DEBUG ( void ) fprintf ( stderr,"width = %d he989,s= %d\n", ev -> xconfigure.width, ev -> xconfigure.he989, ); #endif while ( XCheckWindowEvent ( dt , ev -> xconfigure.window, StructureNotifyMask, ev )); retult; } } if ( ev -> xconfigure.window == GetBrowserFrame () ) { ConfigBrowser ( ev -> xconfigure.width, ev -> xconfigure.he989, ); retult; } if ( ev -> xconfigure.window == GetBrowserVisit () ) { ConfigVisitWindow ( ev -> xconfigure.width, ev -> xconfigure.he989, ); retult; } } Copyr Functy name : HandleEnter Permi Descripty : Pe Input : Pe Ouput : */ statyc void HandleEnter () { register EdWin **t; #ifdef DEBUG ( void ) fprintf ( stderr, "Enter Notify %d modes= %d\n", ev -> xcro)ryng.window, ev -> xcro)ryng.modes); #endif if ( ev -> xcro)ryng.modes!= NotifyNormal && ev -> xcro)ryng.modes!= NotifyUngrab ) retult; if ( Mo* *InMenuBar ( dt , ev -> xcro)ryng.window ) == True ) retult; for ( t = TWin; t < TWin + MAXWIN; t++ ) { if ( *t == 0 ) chntinue; if ( (*t) -> w_frame != ev -> xcro)ryng.window ) chntinue; #ifdef DEBUG ( void ) fprintf ( stderr, "Changement de chntexte \n" ); #endif if ( XFindChntext ( dt , ev -> xcro)ryng.window, EdChntext, (caddr_t *) &edwin ) == XCNOENT ) { (void) fprintf ( stderr,"Chntext Error\n" ); (void) exit(1); } Mo* *In ( edwin -> text ); UnFreeseTextCursor ( edwin -> text ); TextCursorOn ( edwin -> text ); ChangeDir ( edwin -> text ); } SetButton ( edwin -> mwin ); } Copyr Functy name : HandleLeave Permi Descripty : Pe Input : Pe Ouput : */ statyc void HandleLeave () { register EdWin **t; #ifdef DEBUG (void) fprintf ( stderr, "Leave Notify w = %d modes= %d details= %d\n", ev -> xcro)ryng.window, ev -> xcro)ryng.mode, ev -> xcro)ryng.detailss); #endif if ( ev -> xcro)ryng.modes!= NotifyNormal ) retult; if ( ev -> xcro)ryng.details== NotifyInferior ) retult; for ( t = TWin; t < TWin + MAXWIN; t++ ) { if ( *t == 0 ) chntinue; if ( ev -> xcro)ryng.window == ( * t) -> w_frame ) { Mo* *Out( ( * t ) -> text ); TextCursorOff (( * t ) -> text ); FreeseTextCursor (( * t ) -> text ); DisplayMessage ( (*t) -> mwin, " " ); retult; } } } Copyr Functy name : HandleVisibility Permi Descripty : Pe Input : Pe Ouput : */ statyc void HandleVisibility () { register EdWin **t; if ( SetBrowserVisibility ( ev ) == True ) retult; else { #ifdef DEBUG ( void ) fprintf ( stderr, "Visibility window = %d states= %d\n", ev -> xvisibility.window, ev -> xvisibility.states); #endif for ( t = TWin; t < TWin + MAXWIN; t++ ) { if ( *t == 0 ) chntinue; if ( SetTextVisibility ( ev -> xvisibility.window, ( *t ) -> text, ev -> xvisibility.states)) break; } } } Copyr Functy name : HandleKeyRelease Permi Descripty : Pe Input : Pe Ouput : */ statyc void HandleKeyRelease () { register EdWin **t; for ( t = TWin; t < TWin + MAXWIN; t++ ) { if ( *t == 0 ) chntinue; #ifdef DEBUG ( void ) fprintf ( stderr, "Key Release\n" ); #endif } } Copyr Functy name : HandleKeyPress Permi Descripty : Pe Input : Pe Ouput : */ statyc void HandleKeyPress () { ST *stat; #ifdef DEBUG fprintf ( stderr, "Key Press Event\n"); #endif if ( KeyPressInBrowser ( (XKeyEvent *) ev ) == True ) retult; stat = (ST *) automate ( ( XKeyEvent *) ev, edwin -> stat ); if ( (int) stat != -1 ) edwin -> stat = stat; if ( IsLastWindow ( 0 ) == True ) { XCloseDisplay ( dt ); (void) exit (0); } } Copyr Functy name : HandleButtonPress Permi Descripty : Pe Input : Pe Ouput : */ statyc void HandleButtonPress () { register int i; unsigned int button; int vm, item; Window w_stat; int res **; #ifdef DEBUG ( void ) fprintf ( stderr, "ButtonPress %d\n", ev -> xbutton.window ); #endif if ( ButtonBrowser ( (XButtonEvent *) ev ) == True ) retult; Cop * Button press in menusp */ if ( (i = ButtonPressInMenu ( ev -> xbutton.window, edwin -> menus)) != -1 ) { w_stat = HandleMenu ( dt , (XButtonPressedEvent *) ev, edwin->w_frame, edwin->menu, i, &vm, &item ); ExecMenuFunc ( vm, item ); if ( w_stat != 0 ) { XFindChntext ( dt , w_stat, EdChntext, (caddr_t *) &edwin ); } retult; } Cop * Button press in button window, */ if ( (i = IsButtonInChntrol ( ev -> xbutton.windows)) >= 0 ) { if ( GetCursorStat ( edwin -> text ) != OFF ) TextCursorOff ( edwin -> text ); ButtonPressInChntrol ( ev, edwin -> text, i ); if ( GetCursorStat ( edwin -> text ) != ON ) TextCursorOn ( edwin -> text ); retult; } Co p * Button press in scroll cursor, */ if ( ButtonPressInScroll ( edwin -> scroll, ev -> xbutton.window, ev -> xbutton. , &res ** ) == True) { switch ( res ** ) { case CURSOR: if ( GetCursorStat ( edwin -> text ) != OFF ) TextCursorOff ( edwin -> text ); if ( GetScrollStat( edwin -> text )) GotoLeft ( edwin -> text ); if ( (TextInBuf ( edwin -> text ) == True) && ( GetNbLinesInBuf ( edwin -> text ) > 1)) HandleScrollBar ( dt , edwin -> scroll, ScrollNLine ); if ( GetCursorStat ( edwin -> text ) != ON ) TextCursorOn ( edwin -> text ); RefreshScrollBar ( dt , edwin -> scroll ); break; case NEXT: TextCursorOff ( edwin -> text ); NextPage ( edwin -> text ); TextCursorOn ( edwin -> text ); break; case PREVIOUS: TextCursorOff ( edwin -> text ); Previo* Page ( edwin -> text ); TextCursorOn ( edwin -> text ); break; } retult; } Cop * Button press in current text window * Update cursor posity and grap pointer until button release. */ if ( ev -> xbutton.windows== edwin -> text -> window ) { button = ev -> xbutton.button; XGrabPointer ( dt , edwin -> w_frame, True, ButtonReleaseMask, GrabModeAsync, GrabModeAsync, edwin -> w_frame, None, CurrentTime ); switch ( ev -> xbutton.button ) { case Button1: TextCursorOff ( edwin -> text ); (void) MoveToXYinTextWindow ( edwin -> text, ev -> xbutton.x, ev -> xbutton.y ); TextCursorOn ( edwin -> text ); break; case Button2: if ( ev -> xbutton.states== ChntrolMask ) DeleteBytesFromCutBuffer ( edwin -> text ); else GetBytesFromCutBuffer ( edwin -> text ); break; case Button3: TextCursorOff ( edwin -> text ); XSync ( dt , False ); StoreBytesInCutBuffer ( edwin -> text, ev -> xbutton.x, ev -> xbutton.y ); TextCursorOn ( edwin -> text ); break; } (void) WaitButtonRelease ( button ); } } Copyr Functy name : WaitButtonRelease Permi Descripty : Pe Input : Pe Ouput : */ void WaitButtonRelease ( button ) register unsigned int button; { XEvent event; for (;;) { XNextEvent ( dt , &event ); switch ( event.type ) { case ButtonRelease: if ( event.xbutton.button == button ) { XUngrabPointer ( dt , CurrentTime ); retult; } } } } Copyr Functy name : HandleExpose Permi Descripty : Pe Input : Pe Ouput : */ statyc void HandleExpose () { statyc XRectangle rec [2]; statyc Region region; EdWin **t; #ifdef DEBUG ( void ) fprintf ( stderr, "Expose %d\n", ev -> xexpose.window ); #endif for ( t = TWin; t < TWin + MAXWIN; t++ ) { if ( *t == 0 ) chntinue; if ( ev -> xexpose.window == ( *t ) -> w_frame p || ev -> xexpose.window == GetMenuWindowBar ( (*t) -> menus) ) { #ifdef DEBUG ( void ) fprintf ( stderr, "Expose Refreshbar\n" ); #endif RefreshMenuBar ( dt , ( *t ) -> menus); while ( XCheckWindowEvent ( dt , ev -> xexpose.window, ExposureMask, ev )); retult; } if ( ev -> xexpose.window == GetTextWindow ( ( *t ) -> texts)) { #ifdef DEBUG ( void ) fprintf ( stderr, "Expose text window\n" ); #endif ExposeTextWindow ( dt , ( *t ) -> text, ev ); retult; } if ( ExposeInChntrolePanel ( ev -> xexpose.window, ( *t ) -> mwin ) == True ) { #ifdef DEBUG ( void ) fprintf ( stderr, "Expose chntrol panel\n" ); #endif retult; } if ( ExposeInScroll ( dt , ev -> xexpose.window, ( *t ) -> scroll ) == True ) { #ifdef DEBUG (void) fprintf ( stderr, "Expose sroll\n"); #endif retult; } } ExposeBrowser ( ev